package com.dgut.Config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@Order(value = 100)
public class SpringFormConfig extends WebSecurityConfigurerAdapter {

    //@Autowired
    //PasswordEncoder passwordEncoder;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.formLogin()
                .loginPage("/login")
                .usernameParameter("user")
                .passwordParameter("pwd")
                .loginProcessingUrl("/login/form")
                .permitAll()
                .and()
                .logout().logoutUrl("/perform_logout")
                .and()
                .rememberMe()
                .and()
                //.csrf().disable()
                .authorizeRequests()
                .anyRequest().authenticated();
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/error/**", "/dist/**", "/css/**");
    }
}
